package com.yodawnla.littleWar.map;

import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.entity.sprite.TiledSprite;

import android.util.Log;

import com.yodawnla.lib.YoScene;
import com.yodawnla.littleWar.map.Location.State;
import com.yodawnla.littleWar.system.Tex;

public class PhysicalLocation extends Sprite
{
	Location mLocation;
	TiledSprite mStateIndicator;
	
//	public interface State
//	{
//		public static final int NORMAL = 0;
//		public static final int WAR = 1;
//		public static final int PEACE = 2;
//	}
	
	public PhysicalLocation(YoScene scene, float pX, float pY, Location location)
	{
		super(pX, pY, scene.getTexture(Tex.City).deepCopy());

		mLocation = location;
		mLocation.setPhysicalLocation(this);
		
		mStateIndicator = new TiledSprite(0, 0, scene.getTiledTexture(Tex.Tiled.BattleState).deepCopy());
		this.attachChild(mStateIndicator);
		mStateIndicator.setVisible(false);
	}

	public Location getLocation()
	{
		return mLocation;
	}
	
	public void setState(int state)
	{
		Log.e("PhysicalLocation", "set state : " + state);
		switch (state)
		{
		case State.NORMAL:
			mStateIndicator.setVisible(false);
			break;
		case State.PREPARE:
		case State.AT_WAR:
			mStateIndicator.setVisible(true);
			mStateIndicator.setCurrentTileIndex(0);
			break;
		case State.NO_WAR:
			mStateIndicator.setVisible(true);
			mStateIndicator.setCurrentTileIndex(1);
			break;
		}
	}
	
//	public void onClickedEvent()
//	{
//		mLocation.loadNode();
//	}
	
//	public void showLink()
//	{
//		ArrayList<Location> locations = mLocation.getLinkedLocation();
//		
//		for(int i = 0; i < locations.size(); i++) 
//		{
//			Location l = locations.get(i);
//			float x2 = l.getPhysicalLocation().getX();
//			float y2 = l.getPhysicalLocation().getY();
//			
//			final float lineWidth = 5;
//			final Line line = new Line(this.getX() + this.getWidth()/2, this.getY() + this.getHeight()/2, x2 + this.getWidth()/2, y2 + this.getHeight()/2, lineWidth);
//			line.setColor(0, 0, 0);
//
//
//			mScene.attachChild(line);
//		}
//	}
}
